package com.zqs.compareface.utils.impl;


import org.json.JSONArray;
import org.json.JSONObject;


/**
 * @program: FaceCompar
 * @description:
 * @author: ZQS
 * @create: 2021-08-07 23:51
 */
public class JsonUtil{

    public static Object getJson(JSONObject json) {
        /**
         * {"face_token":"781084586bf84ef157bff19a9c2a24e2","user_list":[{"score":100,"group_id":"user","user_id":"boss","user_info":""}]}
         */
        Object score;
        //拿返回的状态
        Object statusKey = json.get("error_msg");
        String statuKeyValue = (String) statusKey;
        if(statuKeyValue.equals("SUCCESS")) {
            JSONObject jsonObject = json.getJSONObject("result");
            JSONArray jsonArray = jsonObject.getJSONArray("user_list");
            JSONObject jsonObject1 = jsonArray.getJSONObject(0);
            score = jsonObject1.get("score");
            try {
                if (score instanceof Float) {
                    Float result = (float) score;
                    return result;
                } else if (score instanceof Double) {
                    Double result = (Double) score;
                    return result;
                } else if (score instanceof Integer) {
                    Integer result = (Integer) score;
                    return result;
                } else if (score instanceof Boolean) {
                    Boolean result = (Boolean) score;
                    return result;
                } else if (null == score) {
                    return null;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (statuKeyValue.equals("18")){
            return false;
        }

        return null;
    }
}
